package com.nbgroup.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.nbgroup.pojo.BusinessRecord;
import com.nbgroup.mapper.BusinessRecordMapper;
import com.nbgroup.pojo.common.PageBean;
import com.nbgroup.service.IBusinessRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商机记录表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-28
 */
@Service
public class BusinessRecordServiceImpl extends ServiceImpl<BusinessRecordMapper, BusinessRecord> implements IBusinessRecordService {

    /**
     * 商机记录列表
     * @param businessId
     * @return
     */
    @Override
    public PageBean queryListRecords(Long businessId) {
        List<BusinessRecord> list = lambdaQuery().eq(BusinessRecord::getBusinessId, businessId).orderBy(true, false, BusinessRecord::getCreateTime).list();
        if (CollectionUtil.isEmpty(list)){
            list = List.of();
        }
        Long size = (long) list.size();
        PageBean pageBean = PageBean.builder().msg("查询成功").rows(list).total(size).code(200).build();
        return pageBean;
    }
}
